import pickle
import numpy as np

# 加载 Q 表
with open('/home/qizui/桌面/2024-NUEDC-E-main/Q_table_dict.pkl', 'rb') as f:
    q_table = pickle.load(f)
# 转换状态为元组，以便用作字典的键
state_to_modify = tuple(map(tuple, [[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]]))
action_to_modify = (1, 1)
new_q_value = 0.99

# 更新 Q 值
if state_to_modify in q_table:
    if action_to_modify in q_table[state_to_modify]:
        q_table[state_to_modify][action_to_modify] = new_q_value
    else:
        q_table[state_to_modify][action_to_modify] = new_q_value
else:
    q_table[state_to_modify] = {action_to_modify: new_q_value}

# 保存修改后的 Q 表
with open('/home/qizui/桌面/2024-NUEDC-E-main/Q_table_dict.pkl', 'wb') as f:
    pickle.dump(q_table, f)
